package com.hongning.railway.ui.main.cadremanager;

import android.arch.lifecycle.ViewModelProviders;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.hongning.railway.R;
import com.hongning.railway.app.AppViewModelFactory;
import com.hongning.railway.app.Constant;
import com.hongning.railway.databinding.FragmentCadregradeBinding;
import com.hongning.railway.entity.resbean.ResCadreBean;
import com.hongning.railway.util.TimeUtils;

import me.goldze.mvvmhabit.BR;
import me.goldze.mvvmhabit.base.BaseFragment;

/**
 * Author: zhangjing
 * DATA:2019-08-29 11:10
 * DESC:
 * email:zhangjingworkmol@163.com
 */
public class CadreGradeFragment extends BaseFragment<FragmentCadregradeBinding,CadreGradeFragmentViewModel> {
    ResCadreBean resCadreBean;
    @Override
    public int initContentView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return R.layout.fragment_cadregrade;
    }
    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public void initParam() {
        super.initParam();
        resCadreBean = getArguments().getParcelable(Constant.EXTRA_DATA);
        if (resCadreBean==null)getActivity().finish();
    }

    @Override
    public void initData() {
        super.initData();
        binding.appTitle.tvTopTitle.setText("干部测评");
        binding.appTitle.ivLeft.setVisibility(View.VISIBLE);
        binding.appTitle.ivLeft.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getActivity().finish();
            }
        });
        viewModel.loadData(resCadreBean.getId());
        viewModel.time.set("考核时间："+ TimeUtils.getFormatTime(resCadreBean.getCreateTime())+"-"+TimeUtils.getFormatTime(resCadreBean.getCadreteststoptime()));
        if ("2".equals(resCadreBean.getHtmlstate())||"3".equals(resCadreBean.getHtmlstate())||"0".equals(resCadreBean.getHtmlstate())){
            viewModel.submitenable.set(false);
            viewModel.enable.set(false);
        }else {
            viewModel.submitenable.set(true);
            viewModel.enable.set(true);
        }
    }

    @Override
    public CadreGradeFragmentViewModel initViewModel() {
        AppViewModelFactory appViewModelFactory = AppViewModelFactory.getInstance(getActivity().getApplication());
        return ViewModelProviders.of(this,appViewModelFactory).get(CadreGradeFragmentViewModel.class);
    }
}
